package com.linkin.homepage.ui.adapter;

import android.content.Context;
import android.view.View;
import android.widget.Toast;

import androidx.recyclerview.widget.RecyclerView;

import com.linkin.homepage.R;
import com.linkin.homepage.base.autolayout.AutoUtils;
import com.linkin.homepage.base.recycleview.BaseItemDecoration;
import com.linkin.homepage.base.recycleview.BaseMultiRCAdapter;
import com.linkin.homepage.base.recycleview.BaseRCViewHolder;
import com.linkin.homepage.base.rxbase.RxManager;
import com.linkin.homepage.bean.ClassItemBean;
import com.linkin.homepage.util.ToastUitl;

public class ComRCAdapter extends BaseMultiRCAdapter {

    private int mClickPosition = -1;
    private RxManager mRxManager = null;

    public ComRCAdapter(Context context) {
        super(context);
    }

    public void setDivider(RecyclerView recyclerView, boolean showFirst, boolean showLast) {
        BaseItemDecoration decoration =
                new BaseItemDecoration(1, showFirst, showLast, false);
        decoration.setDividerColor(0xfff2f2f2);
        decoration.setDividerMarginLeft(AutoUtils.getAutoLayoutSize(recyclerView.getContext(), R.dimen.common_margin));
        decoration.setDividerMarginRight(AutoUtils.getAutoLayoutSize(recyclerView.getContext(), R.dimen.common_margin));
        recyclerView.addItemDecoration(decoration);
    }

    public void setRxManager(RxManager rxManager) {
        mRxManager = rxManager;
    }

    public Object getClickItem() {
        return getItem(mClickPosition);
    }

    public int getClickPosition() {
        return mClickPosition;
    }

    @Override
    protected void onClickView(BaseRCViewHolder holder, int position, View v) {
        super.onClickView(holder, position, v);
        mClickPosition = position;
    }

    @Override
    protected Class getItemHolderClz(Object item, int position) {

        if (item instanceof ClassItemBean) {
            return NewsViewHolder1.class;
        }

        return NewsViewHolder1.class;
    }

    // ClassItem
    @Override
    protected void onBindView1(BaseRCViewHolder viewHolder, int position) {
        NewsViewHolder1 holder = (NewsViewHolder1) viewHolder;
        Object o = getItem(position);
        ClassItemBean item = (ClassItemBean) o;

        holder.setTitle(item.getClass_name());
        holder.itemView.setOnClickListener(this);
    }

    @Override
    protected void onClickView1(BaseRCViewHolder viewHolder, int position, View v) {
        onClickNewsItem(position);
    }

    /**
     * private
     */
    private void onClickNewsItem(int position) {
        ClassItemBean classItem = getItem(position);
        ToastUitl.show("点击了" + classItem.getClass_name(), Toast.LENGTH_SHORT);
    }
}
